<script src="/statics/js/layer.js"></script>
<script class="resources library" src="/statics/js/area.js" type="text/javascript"></script>
<!-- 头部开始 -->
<div class="header">
<!--    <div class="header_r"><img src="img/tx.jpg" width="30"></div>-->
    <div class="header_l"><a href="javascript:history.back(-1)"></a></div>
    <div class="header_m">我的地址</div>
</div>
<!-- 头部结束 -->

<!--店铺基本信息开始-->
<?php if($address){foreach($address AS $val){?>
<div class="address">
    <p class="address-xm"><?=$val['receive_name']?>　　<?=$val['receive_mobile']?></p>
    <p class="address-dz"><?=$val['provice']?><?=$val['city']?><?=$val['area']?><?=$val['street']?></p>
    <div class="add-mo">
		<span>
			<a href="" class="add-mo-bj cd-popup-trigger2" iname="<?=$val['receive_name']?>" iidentity="<?=$val['receive_identity']?>" imobile="<?=$val['receive_mobile']?>" iprovice="<?=$val['provice']?>" icity="<?=$val['city']?>" iarea="<?=$val['area']?>" istreet="<?=$val['street']?>" iid="<?=$val['address_id']?>">编辑</a>
			<a class="add-mo-sc deladdress" itv="<?=$val['address_id']?>" id="test1">删除</a>
		</span>
		<label style="float: left;"><input type="radio" name="default" class="<?php if($val['is_default'] != 1){echo 'default';}?>" itv="<?=$val['address_id']?>" <if condition="$val['is_default'] eq 1">checked</if> />默认地址</label>
	</div>
</div>
<?php }}?>
<div class="add cd-popup-trigger2">+ 新建地址</div>
<!--店铺基本信息结束-->
    
<!--新增地址开始-->
<div class="cd-popup2" role="alert">
    <div class="cd-popup-container2">
        <div id="PopupLayer2" class="PopupLayer2"><a class="close cd-popup-close2"></a>
            <p class="xd-dz">新增收货地址</p>
            <div class="xd-xzdz2"><span>姓　名：</span><input type="text" placeholder="请输入真实姓名" class="needval" id="nameval"></div>
            <div class="xd-xzdz2"><span>身份证：</span><input type="text" placeholder="请输入真实身份证号码" class="needval" id="cardval"></div>
            <div class="xd-xzdz2 id-u"><span>身份证号码用于海关检查</span><em></em></div>
            <div class="xd-xzdz2"><span>电　话：</span><input type="text" placeholder="请输入手机号" class="needval" id="mobileval"></div>
            <div class="xd-xzdz2"><span>地　区：</span>
                <div class="ldcs">
                    <select id="s_province" name="s_province" class="needval"></select>  
                    <select id="s_city" name="s_city" class="needval"></select>  
                    <select id="s_county" name="s_county" class="needval"></select>
					<input type="hidden" value="" id="iid" />
                    <script type="text/javascript">_init_area();</script>
                </div>
            </div>
            <div class="xd-xzdz2"><span>地　址：</span><input type="text" placeholder="请选择地址" class="needval" id="streetval"></div>
            <p class="canshu_n"><a href="javascript:void(0)" id="putAddressAdd" onClick="checkSubmitMobil()">确定</a></p>
        </div>
    </div>
</div>
<!--新增地址结束-->

<div class="fiex nav"> <a class="icon-shouye" href="/index/index/sek/<?=$sek?>"><br />
  首页</a> <a class="icon-fenlei" href="/cate/main/sek/<?=$sek?>"><br />
  分类</a> <a class="icon-gouwu" href="/cart/index/sek/<?=$sek?>"><br />
  购物车</a> <a class="icon-geren fiex_on" href="/index/user/sek/<?=$sek?>"><br />
  用户中心</a> </div>
    
<script>
$(function(){
	$('#putAddressAdd').click(function(){
		mcontinue = 1;
		$('.needval').each(function(){
			if(!$(this).val()){
				layer.msg($(this).attr('placeholder'), {icon: 0});
				mcontinue = 0;return false;
			}else{
                
				if (!$("#mobileval").val().match(/^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1})|(14[0-9]{1})|(17[0-9]{1}))+\d{8})$/)) { 
				layer.msg('手机号码有误', {icon: 0});
				mcontinue = 0;return false; 
			} 
			}
		}); 
		
		if(mcontinue > 0){
			$.post('/order/addAddress',{'dosubmit':'1','id':$('#iid').val(),'name':$('#nameval').val(),'identity':$('#cardval').val(),'mobile':$('#mobileval').val(),'provice':$('#s_province').val(),'city':$('#s_city').val(),'area':$('#s_county').val(),'street':$('#streetval').val()},function(data){
				layer.msg(data.msg, {icon: data.code});
				setTimeout(function(){location.reload();},1000);
			},'json');
		}
	});
	
	$('.add-mo-bj').click(function(){
		_this = $(this);
		$('#nameval').val($(this).attr('iname'));
		$('#cardval').val($(this).attr('iidentity'));
		$('#mobileval').val($(this).attr('imobile'));
		$('#s_province').val($(this).attr('iprovice'));
		$('#s_province').change(function(){
			setTimeout(function(){
				$('#s_city').val(_this.attr('icity'));
				$('#s_city').change(function(){
					setTimeout(function(){$('#s_county').val(_this.attr('iarea'));},400);
				}).trigger('change');
			},400);
		}).trigger('change');
		$('#streetval').val($(this).attr('istreet'));
		$('#iid').val($(this).attr('iid'));
	});
	$('.add').click(function(){
		$('#nameval').val('');
		$('#mobileval').val('');
		$('#s_province').val('');
		$('#s_city').val('');
		$('#s_county').val('');
		$('#streetval').val('');
		$('#iid').val('');
	});
	$('.deladdress').click(function(){
		_this = $(this);
		layer.confirm('确认删除吗 ?', { btn: ['确认','取消']},       
               function(){
					$.get('/order/deladdress',{'id':_this.attr('itv')},function(data){
						layer.msg(data.msg, {icon: data.code});
						setTimeout(function(){location.reload();},1000);
					},'json');
   			   },    
               function(){});
	});

	//设置默认地址
	$('.default').click(function(){
		_this = $(this);
		$.get('/order/dfaddress',{'id':_this.attr('itv')},function(data){
			layer.msg(data.msg,{icon: data.code});
			setTimeout(function(){location.reload();},1000);
		},'json');
	});
})
</script>